package de.gwtprime.client;


import com.google.gwt.core.client.GWT;
import com.google.gwt.event.shared.SimpleEventBus;
import com.google.gwt.place.shared.PlaceController;
import com.google.web.bindery.event.shared.EventBus;

import de.gwtprime.client.views.ArticleOverviewView;
import de.gwtprime.client.views.ArticleOverviewViewImpl;
import de.gwtprime.client.views.ArticleSectionView;
import de.gwtprime.client.views.ArticleSectionViewImpl;
import de.gwtprime.client.views.ArticleView;
import de.gwtprime.client.views.ArticleViewImpl;
import de.gwtprime.client.views.FooterView;
import de.gwtprime.client.views.FooterViewImpl;
import de.gwtprime.client.views.ImpressumView;
import de.gwtprime.client.views.ImpressumViewImpl;
import de.gwtprime.client.views.QuestionView;
import de.gwtprime.client.views.QuestionViewImpl;
import de.gwtprime.client.views.UserAccountView;
import de.gwtprime.client.views.UserAccountViewImpl;
import de.gwtprime.client.views.WelcomeView;
import de.gwtprime.client.views.WelcomeViewImpl;
import de.gwtprime.client.viewsStatic.GreenHeadView;
import de.gwtprime.client.viewsStatic.GreenHeadViewImpl;
import de.gwtprime.client.viewsStatic.NavigationViewImpl;
import de.gwtprime.client.widgets.notificationCenter.NotificationCenterWidget;
import de.gwtprime.shared.requestFactory.User2Proxy;

public class ClientFactoryImpl implements ClientFactory {

	private final EventBus eventBus = new SimpleEventBus();
	private final PlaceController placeController = new PlaceController(getEventBus());
	private final ArticleView articleView= new ArticleViewImpl(this);
	private final ImpressumView impressumView= new ImpressumViewImpl();
	private WelcomeView welcomeView;
	private final PrimeServiceAsync primeService = GWT.create(PrimeService.class);
	private final NavigationViewImpl navigationView = GWT.create(NavigationViewImpl.class);
	private final FooterViewImpl footerView = GWT.create(FooterViewImpl.class);
	private final GreenHeadView greenView = GWT.create(GreenHeadViewImpl.class);
	private final UserAccountView userAccountView = GWT.create(UserAccountViewImpl.class);
	private ArticleOverviewView articleOverview = null;
	private ArticleSectionView articleSectionView = null;

	private QuestionView questionView = null;
	private NotificationCenterWidget notificationCenter;

	private PrimeRequestFactory requestFactory = null;
	private User2Proxy user;

	@Override
	public EventBus getEventBus() {
		return eventBus;
	}

	@Override
	public PlaceController getPlaceController() {
		
		return placeController;
	}

	@Override
	public ArticleView getArticleView() {
		return articleView;
	}

	@Override
	public ImpressumView getImpressumView() {
		return impressumView;
	}

	@Override
	public PrimeServiceAsync getPrimeService() {
		return primeService;
	}


	@Override
	public WelcomeView getWelcomeView() {
		
		if(welcomeView==null)
			welcomeView = new WelcomeViewImpl();
		return welcomeView;
	}

	@Override
	public NavigationViewImpl getNavigationView() {
		return navigationView;
	}

	@Override
	public GreenHeadView getGreenHeadView() {
		return greenView;
	}

	@Override
	public FooterView getFooterView() {
		return footerView;
	}

	@Override
	public UserAccountView getUserAccountView() {
		return userAccountView;
	}


	public PrimeRequestFactory getRequestFactory() {
		if(requestFactory==null){
			requestFactory = GWT.create(PrimeRequestFactory.class);
			requestFactory.initialize(eventBus);
		}
		return requestFactory;
	}

	@Override
	public User2Proxy getUser() {
		return user;
	}

	@Override
	public void setUser(User2Proxy user) {
		this.user = user;
	}

	@Override
	public QuestionView getQuestionView() {
		if(questionView==null)
			questionView = new QuestionViewImpl(this);

		return questionView;
	}

	@Override
	public NotificationCenterWidget getNotificationCenter() {
		if(notificationCenter==null)
			notificationCenter = new NotificationCenterWidget(this);
		
		return notificationCenter;
	}

	@Override
	public ArticleOverviewView getArticleOverviewWidget() {
		
		if(articleOverview == null)
			articleOverview = new ArticleOverviewViewImpl(this);
		return articleOverview;
	}

	@Override
	public ArticleSectionView getArticleSectionView() {
		if(articleSectionView == null)
			articleSectionView = new ArticleSectionViewImpl(this);
		return articleSectionView;
	}

	//	@Override
	//	public ArticlePreviewWidget getArticlePreviewWidget() {
	//		if(articlePreviewWidget==null)
	//			articlePreviewWidget = GWT.create(ArticlePreviewWidgetImpl.class);
	//		
	//		return articlePreviewWidget;
	//	}


}
